#include "flow3dnode.h"

#include <vector>
#include <iostream>
using std::cout;
using std::endl;

#include "marchingcubes.h"




Flow3DNode::Flow3DNode()
{
    // Use for culling and hiding objects
    float _size = 3;
    setSurroundingSphere( Sphere<GLfloat,3>( Point3D<GLfloat>(0.0,0.0,0.0), _size ) );

    // Drop the line above if you want to make the surrounding sphere visible
    // _sphere = new Sphere3D( _size );
    // setSurroundingsShpere( _sphere );

    _f3d_data = 0x0;
    frame = 0;
    animTimer = 0.0;

		mcubes = new MarchingCubes();
}


void Flow3DNode::localDisplay() {

	glDisable(GL_LIGHTING);

	if( _f3d_data != 0x0 )
	if( _f3d_data->isValid() )
	{
		
		mcubes->localDisplay();
	}

	glEnable(GL_LIGHTING);

	// Display the surrounding sphere
	// _sphere->display();
}


void Flow3DNode::localSelect() {
    localDisplay();
}


void Flow3DNode::localSimulate( double dt ) {

	if(_f3d_data != 0x0)
	{
    animTimer += dt;
    if(animTimer > 1.5)
    {
        animTimer=0;
        frame++;

				

        if( frame > _f3d_data->getNumFrames()-1 )
        {
            frame = 0;
        }

				mcubes->setFrame(frame);
				std::cout << "frame: " << (frame+1) << "/" << _f3d_data->getNumFrames() << std::endl;
    }
	}
}


void Flow3DNode::setF3DData( Flow3DData  *f3d_data)
{
    _f3d_data = f3d_data;
		mcubes->setData( _f3d_data );
}

